﻿//======================================================
//==     (c)2008 aspxcms inc by NeTCMS v1.0              ==
//==          Forum:bbs.aspxcms.com                   ==
//==         Website:www.aspxcms.com                  ==
//======================================================
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NetCMS.Content;
using NetCMS.Model;

public partial class manage_channel_Special_list : NetCMS.Web.UI.ManagePage
{
    public manage_channel_Special_list()
    {
        this.Authority_Code = "D007";
    }
    Channel rd = new Channel();
    public static string ChID = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        this.CheckAdminAuthority();
        this.PageNavigator1.OnPageChange += new PageChangeHandler(PageNavigator1_PageChange);
        if (!IsPostBack)
        {
            if (SiteID != "0")
            {
                PageError("分站没权限操作", "javascript:history.back();", true);
            }
            ChID = Request.QueryString["ChID"];
            string ParentID = Request.QueryString["ParentID"];
            if (ChID != null && ChID != string.Empty)
            {
                copyright.InnerHtml = CopyRight;
                if (Request.QueryString["Type"] != string.Empty && Request.QueryString["Type"] != null)
                {
                    string specialID = Request.QueryString["SpecialId"];
                    string oRderID = Request.QueryString["OrderId"];
                    if (specialID != string.Empty && specialID != null && oRderID != string.Empty && oRderID != null)
                    {
                        rd.updateOrder(int.Parse(specialID.ToString()), int.Parse(oRderID.ToString()), 1);
                        PageRight("权重更新为：" + oRderID.ToString() + "成功", "javascript:history.back();", true);
                    }
                }
            }
            else
            {
                PageError("错误的参数", "javascript:history.back();", true);
            }
            StartLoad(1);
        }
    }
    //分页处理
    protected void PageNavigator1_PageChange(object sender, int PageIndex)
    {
        StartLoad(PageIndex);
    }
    //数据初始化
    protected void StartLoad(int PageIndex)
    {
        int i, j;
        SQLConditionInfo[] st = new SQLConditionInfo[2];
        st[0] = new SQLConditionInfo("@ChID", int.Parse(ChID.ToString()));
        st[1] = new SQLConditionInfo("@ParentID", 0);
        DataTable dt = Pagination.GetPage(this.GetType().Name, PageIndex, 50, out i, out j, st);
        this.PageNavigator1.PageCount = j;
        this.PageNavigator1.PageIndex = PageIndex;
        this.PageNavigator1.RecordCount = i;
        string strchar = string.Empty;
        if (dt != null && dt.Rows.Count > 0)
        {
            dt.Columns.Add("CName", typeof(string));
            dt.Columns.Add("OrderIDs", typeof(string));
            dt.Columns.Add("ST", typeof(string));
            dt.Columns.Add("OP", typeof(string));
            dt.Columns.Add("Colum", typeof(string));
            for (int k = 0; k < dt.Rows.Count; k++)
            {
                dt.Rows[k]["CName"] = "<a href=\"Special_add.aspx?sId=" + dt.Rows[k]["ID"].ToString() + "&ChID=" + ChID + "&Action=Edit\" class=\"list_link\" title=\"点击修改\">" + dt.Rows[k]["specialCName"].ToString() + "(" + dt.Rows[k]["specialEName"].ToString() + ")</a>";
                dt.Rows[k]["OrderIDs"] = "<a href=\"javascript:orderAction(" + dt.Rows[k]["ID"] + "," + dt.Rows[k]["OrderID"] + ");\" class=\"list_link\" title=\"点击修改权重\"><strong>" + dt.Rows[k]["OrderID"].ToString() + "</strong></a>";
                if (dt.Rows[k]["islock"].ToString() == "1")
                {
                    dt.Rows[k]["ST"] = "&nbsp;&nbsp;<span class=\"reshow\">已锁定</span>&nbsp;&nbsp;";
                }
                else
                {
                    dt.Rows[k]["ST"] = "&nbsp;&nbsp;正常&nbsp;&nbsp;";
                }
                dt.Rows[k]["OP"] += "<input type=\"checkbox\" Name=\"gID\" value=\"" + dt.Rows[k]["id"].ToString() + "\">";
                dt.Rows[k]["OP"] += "<a href=\"Special_add.aspx?ChID=" + Request.QueryString["ChID"] + "&sId=" + dt.Rows[k]["id"].ToString() + "&Action=Edit\"><img src=\"../../sysImages/" + NetCMS.Config.UIConfig.CssPath() + "/sysico/edit.gif\" border=\"0\"></a>";
                dt.Rows[k]["OP"] += "<a href=\"preview.aspx?ChID=" + Request.QueryString["ChID"] + "&id=" + dt.Rows[k]["id"].ToString() + "&type=special\"  target=\"_blank\"><img src=\"../../sysImages/" + NetCMS.Config.UIConfig.CssPath() + "/sysico/review.gif\" border=\"0\"></a>";
                dt.Rows[k]["OP"] += "<a href=\"Special_add.aspx?ChID=" + Request.QueryString["ChID"] + "&SpecialID=" + dt.Rows[k]["id"].ToString() + "\"><img src=\"../../sysImages/" + NetCMS.Config.UIConfig.CssPath() + "/sysico/addclass.gif\" border=\"0\"></a>";
                string TmpFolder = string.Empty;
                string TmpSTR = string.Empty;
                int ClassNumber = rd.getSpecialNumber(int.Parse(dt.Rows[k]["id"].ToString()));
                if (ClassNumber > 0)
                {
                    TmpFolder = "<img src=\"../../sysImages/folder/yess.gif\" border=\"0\" title=\"此专题下有" + ClassNumber + "个专题\">";
                    TmpSTR = "<a href=\"###\" class=\"list_link\" onclick=\"ajaxGetClass('" + dt.Rows[k]["id"].ToString() + "','div_" + dt.Rows[k]["id"].ToString() + "','')\">" + TmpFolder + "</a>";
                }
                else
                {
                    TmpFolder = "<img src=\"../../sysImages/folder/nos.gif\" border=\"0\" title=\"此专题下有0个专题\">";
                    TmpSTR = TmpFolder;
                }
                strchar += "<div style=\"padding:3px 10px;\">";
                strchar += "(" + dt.Rows[k]["OrderIDs"] + ")&nbsp;";
                strchar += TmpSTR + "<span class=\"reshow\">(" + ClassNumber + ")</span>" + dt.Rows[k]["specialCName"] + "&nbsp;<a title=\"此专题下的信息\" href=\"Content.aspx?ChID=" + Request.QueryString["ChID"] + "&stat=SP|" + dt.Rows[k]["id"].ToString() + "\">[" + rd.GetSpecialInfoCount(int.Parse(dt.Rows[k]["id"].ToString()), int.Parse(Request.QueryString["ChID"].ToString())) + "]</a>";
                strchar += dt.Rows[k]["ST"];
                strchar += dt.Rows[k]["OP"];
                strchar += "<div style=\"width:100%;display:none;padding-left:10px;\" id=\"div_" + dt.Rows[k]["id"].ToString() + "\">loading...";
                strchar += "</div></div>";
            }
            dt.Rows[0]["Colum"] = strchar;

        }
        DataList1.DataSource = dt;
        DataList1.DataBind();
    }

    protected void Reset_allClass(object sender, EventArgs e)
    {
        string Str = Request.Form["gID"];
        if (Str == null || Str == String.Empty)
        {
            PageError("请至少选择一项!", "");
        }
        else
        {
            string[] gIDARR = Str.Split(',');
            Str = null;
            int j = 0;
            int m = 0;
            for (int i = 0; i < gIDARR.Length; i++)
            {
                if (rd.Reset_allSpecial(int.Parse(gIDARR[i]), int.Parse(Request.QueryString["ChID"].ToString())) != 0)
                {
                    j++;
                }
                else
                {
                    m++;
                }
            }
            PageRight("成功删除" + j + "个专题下的新闻!,失败" + m + "个(没有找到记录)。", "special_list.aspx?ChID=" + Request.QueryString["ChID"] + "", true);
        }
    }

    protected void Lock_allClass(object sender, EventArgs e)
    {
        string Str = Request.Form["gID"];
        if (Str == null || Str == String.Empty)
        {
            PageError("请至少选择一项!", "");
        }
        else
        {
            string[] gIDARR = Str.Split(',');
            Str = null;
            int j = 0;
            int m = 0;
            for (int i = 0; i < gIDARR.Length; i++)
            {
                if (rd.lockstatSpecial(int.Parse(gIDARR[i]), 1) != 0)
                {
                    j++;
                }
                else
                {
                    m++;
                }
            }
            PageRight("成功锁定" + j + "个专题!,失败" + m + "个。", "special_list.aspx?ChID=" + Request.QueryString["ChID"] + "", true);
        }
    }

    protected void UnLock_allClass(object sender, EventArgs e)
    {
        string Str = Request.Form["gID"];
        if (Str == null || Str == String.Empty)
        {
            PageError("请至少选择一项!", "");
        }
        else
        {
            string[] gIDARR = Str.Split(',');
            Str = null;
            int j = 0;
            int m = 0;
            for (int i = 0; i < gIDARR.Length; i++)
            {
                if (rd.lockstatSpecial(int.Parse(gIDARR[i]), 0) != 0)
                {
                    j++;
                }
                else
                {
                    m++;
                }
            }
            PageRight("成功解锁" + j + "个专题!,失败" + m + "个。", "special_list.aspx?ChID=" + Request.QueryString["ChID"] + "", true);
        }
    }

    protected void MakeHtml(object sender, EventArgs e)
    {
        string Str = Request.Form["gID"];
        int ChID = int.Parse(Request.QueryString["ChID"].ToString());
        if (Str == null || Str == String.Empty)
        {
            PageError("请至少选择一项!", "");
        }
        else
        {
            NetCMS.Control.HProgressBar.Start();
            NetCMS.Publish.General PG = new NetCMS.Publish.General();
            try
            {
                NetCMS.Control.HProgressBar.Roll("正在发布频道专题", 0);
                string[] Checkboxs = Str.Split(',');
                Str = null;
                int j = 0;
                int m = Checkboxs.Length;
                for (int i = 0; i < m; i++)
                {
                    if (PG.publishCHSingleSpecial(int.Parse(Checkboxs[i].ToString()), ChID))
                    {
                        j++;
                    }
                    NetCMS.Control.HProgressBar.Roll("共生成" + m + "个频道专题，正在发布" + (i + 1) + "个。", ((i + 1) * 100 / m));
                }
                NetCMS.Control.HProgressBar.Roll("发布频道专题成功,成功" + j + "个,<a class=\"list_link\" href=\"../Publish/error/geterror.aspx?\">失败" + (Checkboxs.Length - j) + "个</a>. &nbsp;<a class=\"list_link\" href=\"javascript:history.back();\">返回</a>", 100);
            }
            catch (Exception ex)
            {
                NetCMS.Common.Public.savePublicLogFiles("□□□发布专题,频道ID" + ChID.ToString() + "", "【错误描述：】\r\n" + ex.ToString(), UserName);
                NetCMS.Control.HProgressBar.Roll("发布频道专题失败。<a  class=\"list_link\"href=\"../publish/error/geterror.aspx?\">查看日志</a>", 0);
            }
            Response.End();
        }
    }

    protected void Makexml(object sender, EventArgs e)
    {

    }

    protected void delClass(object sender, EventArgs e)
    {
        string Str = Request.Form["gID"];
        if (Str == null || Str == String.Empty)
        {
            PageError("请至少选择一项!", "");
        }
        else
        {
            string[] gIDARR = Str.Split(',');
            Str = null;
            int j = 0;
            int m = 0;
            for (int i = 0; i < gIDARR.Length; i++)
            {
                if (rd.delSpecial(int.Parse(gIDARR[i])) != 0)
                {
                    j++;
                }
                else
                {
                    m++;
                }
            }
            PageRight("成功删除" + j + "个专题!,失败" + m + "个专题。", "special_list.aspx?ChID=" + Request.QueryString["ChID"] + "", true);
        }
    }
}
